home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: A beginners valiant effort.
- Date: Mon, 19 Feb 1996 18:47:25 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4gagir$907@news.halcyon.com>
- References: <4g81kr$mrs@soap.news.pipex.net>
- NNTP-Posting-Host: blv-pm12-ip19.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- It does work. But you made an off-by-one error in your buffers:
- "is not flowering" is 17 characters, counting the null terminator.
-
- class switc_string
- {
- private:
- char string_val_one[20];
- char string_val_two[20];
- ...
- };
-
-
- s1.get_string(true);
-
- will correctly print out "1Is not flowering"
-
- Step through your program with a debugger, btw, and you *might* have
- noticed string_val_one suddenly grow with string_val_two's assignment,
- although that depends on packing factor. But you'd definitely have
- seen the control flow never enter the else clause.
-
- BTW, we've all made off-by-one errors in our careers; it's insidious.
-
- --Norm
-
-
- chris.neale@ooh.conqueror.co.uk (Chris Neale) wrote:
-
- >Please, Please! Help! Why doesn't this work - the book says it should,
- >but the IF statement falls through - like a switch statement. Try it
- >and see.
-
- >Thanks, Chris
-
- >please e-mail responses to neales@dial.pipex.com - Ta.
-
-
- >#include <iostream.h>
- >#include <string.h>
-
- >enum boolean{false, true};
-
- >class switc_string
- > {
- > private:
- > char string_val_one[16];
- > char string_val_two[12];
- > public:
- > void set_string(char string1[], char string2[])
- > {
- > strcpy(string_val_one, string1);
- > strcpy(string_val_two, string2);
- > }
- > void get_string(boolean string_index)
- > {
- > cout << string_index;
- > if ( string_index )
- > {cout << string_val_one;}
-
- > else
- > {cout << string_val_two;}
- > }
- > };
-
- >void main()
-
- >{
-
- >switc_string s1;
- >s1.set_string("is not flowering","is flowering");
- >cout << endl;
- >s1.get_string(1);
-
- >}
-
-
-
-
-